﻿<!-- #include file="../Include/Admin_Onlogin.asp" -->
<%
Data_Name = "{prefix}Moban"
strFileName = "Admin_Template.asp"
Dim sqlAuth, rsAuth, PurviewID
sqlAuth = "Select AuthID From Admin_Auth Where href='Admin/" & strFileName & "?ChannelID="&ChannelID&"' Order By sort Asc,AuthID Asc"
Call Exec(rsAuth,sqlAuth,2)
If rsAuth.BOF And rsAuth.EOF Then
	PurviewID = 0
Else
	PurviewID = rsAuth(0)
	CheckPurview PurviewID,0
End If
rsAuth.Close
Set rsAuth = Nothing
Dim TopDir,FsoFile,AllFileSize
Dim DirFiles,DirFolder
Set Fso=Server.CreateObject(Fso_Sys)
TopDir=Replace(InstallDir&TemplateDir&ChannelDir&"/","//","/")
Select Case Action
Case "Add"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='Template/Add' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,0
	Else
		CheckPurview rsAuth(0),0
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call Add()
Case "SaveAdd"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='Template/Insert' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,1
	Else
		CheckPurview rsAuth(0),1
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call SaveAdd()
Case "Modify"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='Template/Edit' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,0
	Else
		CheckPurview rsAuth(0),0
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call Modify()
Case "SaveModify"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='Template/Update' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,1
	Else
		CheckPurview rsAuth(0),1
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call SaveModify()
Case "Update"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='Template/Update' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,1
	Else
		CheckPurview rsAuth(0),1
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call Update()
Case "TemplatePreview"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='Template/View' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,0
	Else
		CheckPurview rsAuth(0),0
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call TemplatePreview()
Case "ModifyContent"
    Call ModifyContent()
Case "Del"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='Template/Del' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,1
	Else
		CheckPurview rsAuth(0),1
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call DelAll()
Case Else
    Call Main()
End Select
If FoundErr = True Then
	Call WriteErrMsg(ErrMsg, ComeUrl)
End If
Call CloseConn()

Sub Main()
	If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
		On Error Resume Next
		ChannelID = Trim(Code_Form("ChannelID"))
		TopDir=Replace(InstallDir&TemplateDir&ChannelDir&"/","//","/")
		Set FsoFile = Fso.GetFolder(Server.MapPath(TopDir))
		If Err or TopDir="/" Then
			Set FsoFile = nothing
			Response.Write "{""code"":201,""msg"":""\u627e\u4e0d\u5230\u76ee\u5f55\uff0c\u53ef\u80fd\u53c2\u6570\u914d\u7f6e\u9519\u8bef\uff01""}" & vbCrLf
			Response.End()
		End If
		AllFileSize = FsoFile.size
		Dim FileNums,i,totalPut,data
		FileNums = FsoFile.Files.count
		totalPut = FileNums
		i=0
		For Each DirFiles in FsoFile.Files
			strFileType=lcase(mid(DirFiles.Name,instrrev(DirFiles.Name,".")+1))
			If strFileType="html" Then
				If i=0 Then
					data = data & "{""name"":"""&ToUnicode(DirFiles.name)&""",""getname"":"""&ToUnicode(GetMobanName(ChannelDir&"/"&DirFiles.name))&""",""gettype"":"""&ToUnicode(GetMobanTypeName(ChannelDir&"/"&DirFiles.name))&""",""ico"":""../Plugins/assets/images/ext/html.png"",""size"":"""&GetSize(DirFiles.size,"b")&""",""time"":"""&Time_Type(DirFiles.DateLastModified,1)&"""}"
				Else
					data = data & ",{""name"":"""&ToUnicode(DirFiles.name)&""",""getname"":"""&ToUnicode(GetMobanName(ChannelDir&"/"&DirFiles.name))&""",""gettype"":"""&ToUnicode(GetMobanTypeName(ChannelDir&"/"&DirFiles.name))&""",""ico"":""../Plugins/assets/images/ext/html.png"",""size"":"""&GetSize(DirFiles.size,"b")&""",""time"":"""&Time_Type(DirFiles.DateLastModified,1)&"""}"
				End If
				i=i+1
			End If
		Next
		Set FsoFile = nothing
		If totalPut = 0 Then
			Response.Write "{""code"":201,""msg"":""\u65e0\u6570\u636e""}" & vbCrLf
		Else
			Response.Write "{""code"":0,""msg"":""\u83b7\u53d6\u6210\u529f!"",""count"":"&totalPut&",""data"":["&data&"],""rel"":1}" & vbCrLf
		End If
		Response.End()
	Else
		Response.Write "<!DOCTYPE html>" & vbCrLf
		Response.Write "<head>" & vbCrLf
		Response.Write "<title>模板管理</title>" & vbCrlf
		Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" & vbCrLf
		Response.Write "<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1'>" & vbCrLf
		Response.Write "<meta name='apple-mobile-web-app-status-bar-style' content='black'>" & vbCrLf
		Response.Write "<meta name='apple-mobile-web-app-capable' content='yes'>" & vbCrLf
		Response.Write "<meta name='format-detection' content='telephone=no'>" & vbCrLf
		Response.Write "<link rel=""stylesheet"" type=""text/css"" href=""../fonts/font-awesome/css/font-awesome.min.css"" />" & vbCrLf
		Response.Write "<link href='../Plugins/layui/css/layui.css' rel='stylesheet' type='text/css' />" & vbCrLf
		Response.Write "<link rel=""stylesheet"" href=""../Style/global.css"" media=""all"">" & vbCrLf
		Response.Write "<link rel=""stylesheet"" href=""../Style/font.css"" media=""all"">" & vbCrLf
		Response.Write "<script type='text/javascript'>" & vbCrLf
		Response.Write "var pc_file = '" & InstallDir & "';" & vbCrLf
		Response.Write "var admin_file = '" & AdminFolder & "/';" & vbCrLf
		Response.Write "</script>" & vbCrLf
		Response.Write "<script type='text/javascript' src='../Js/Admin.js'></script>" & vbCrLf
		Response.Write "<script type='text/javascript' src='../../Dialog/main.js'></script>" & vbCrLf
		Response.Write "<script type='text/javascript' src='../../Dialog/lhgcore.min.js'></script>" & vbCrLf
		Response.Write "<script type='text/javascript' src='../../Dialog/lhgcalendar.min.js'></script>" & vbCrLf
		Response.Write "<script type=""text/javascript"" src=""../Plugins/layui/layui.js""></script>" & vbCrLf
		Response.Write "</head>" & vbCrlf
		Response.Write "<body>" & vbCrlf
		Response.Write "<div class=""admin-main layui-anim layui-anim-upbit"">" & vbCrLf
		Response.Write "    <fieldset class=""layui-elem-field layui-field-title"">" & vbCrLf
		Response.Write "        <legend>模板管理</legend>" & vbCrLf
		Response.Write "    </fieldset>" & vbCrLf
		Response.Write "    <blockquote class=""layui-elem-quote"">" & vbCrLf
		Response.Write "        <a href=""?Action=Add&ChannelID=" & ChannelID & """ class=""layui-btn layui-btn-sm"">" & vbCrlf
		Response.Write "            <i class=""fa fa-plus""></i> 添加模板" & vbCrlf
		Response.Write "        </a>" & vbCrLf
		Response.Write "    </blockquote>" & vbCrLf
		Response.Write "    <table class=""layui-table"" id=""list"" lay-filter=""list""></table>" & vbCrLf
		Response.Write "</div>" & vbCrLf
		Response.Write "<script type=""text/html"" id=""name"">" & vbCrLf
		Response.Write "    <img src=""{{d.ico}}"" style=""width:30px;margin-right:10px"">{{d.name}}" & vbCrlf
		Response.Write "</script>" & vbCrLf
		Response.Write "<script type=""text/html"" id=""getname"">" & vbCrLf
		Response.Write "    <span onmouseover=""layer.tips('单击重命名',this,{tips: [1, '#000']});"" onmouseout=""layer.closeAll();"">{{d.getname}}</span>" & vbCrlf
		Response.Write "</script>" & vbCrLf
		Response.Write "<script type=""text/html"" id=""action"">" & vbCrLf
		Response.Write "    <a href=""?Action=Modify&TemplateName={{d.name}}&ChannelID="&ChannelID&""" class=""layui-btn layui-btn-xs""><i class=""fa fa-edit""></i> 编辑</a>" & vbCrlf
		Response.Write "    <a onClick=""ItemDialog('MobanView','浏览文件！','" & TopDir & "{{d.name}}',800,500);"" class=""layui-btn layui-btn-xs layui-btn-normal""><i class=""fa fa-chrome""></i> 浏览</a>" & vbCrlf
		Response.Write "    <a class=""layui-btn layui-btn-xs layui-btn-danger"" lay-event=""del""><i class=""fa fa-trash-o""></i> 删除</a>" & vbCrLf
		Response.Write "        <a href=""?Action=TemplatePreview&TemplateName={{d.name}}&ChannelID="&ChannelID&""" target=""_blank"" class=""layui-btn layui-btn-xs layui-btn-normal""><i class=""fa fa-eye""></i> 预览</a>" & vbCrLf
		Response.Write "</script>" & vbCrLf
		Response.Write "<script>" & vbCrLf
		Response.Write "    layui.use('table', function() {" & vbCrLf
		Response.Write "        var table = layui.table, $ = layui.jquery;" & vbCrLf
		Response.Write "        var tableIn=table.render({" & vbCrLf
		Response.Write "            elem: '#list'," & vbCrLf
		Response.Write "            url: '?Action=Main'," & vbCrLf
		Response.Write "            method: 'post'," & vbCrLf
		Response.Write "            where: {//设定异步数据接口的参数" & vbCrLf
		Response.Write "                ChannelID: '"&ChannelID&"'" & vbCrLf
		Response.Write "            }," & vbCrLf
		Response.Write "            cellMinWidth: 80," & vbCrLf
		Response.Write "            cols: [[" & vbCrLf
		Response.Write "                {field: 'name', title: '文件名称', width: 200, templet: '#name', fixed: true}," & vbCrLf
		Response.Write "                {field: 'getname', title: '文件别名', width: 200, templet: '#getname', edit: 'text'}," & vbCrLf
		Response.Write "                {field: 'gettype', title: '模板类型', width: 100}," & vbCrLf
		Response.Write "                {field: 'size', title: '文件大小', width: 200}," & vbCrLf
		Response.Write "                {field: 'time', title: '修改时间', width: 160}," & vbCrLf
		Response.Write "                {title: '操作', width: 300, align: 'center', toolbar: '#action'}" & vbCrLf
		Response.Write "            ]]" & vbCrLf
		Response.Write "        });" & vbCrLf
		Response.Write "        //监听单元格编辑" & vbCrlf
		Response.Write "        table.on('edit(list)',function(obj) {" & vbCrlf
		Response.Write "            var value = obj.value, data = obj.data, field = obj.field;" & vbCrlf
		Response.Write "            $.ajax({" & vbCrLf
		Response.Write "                type: 'post'," & vbCrLf
		Response.Write "                url: '?Action=Update'," & vbCrLf
		Response.Write "                data: {TemplateName:data.name,TemplateGetName:value,ChannelID:'"&ChannelID&"'}," & vbCrLf
		Response.Write "                dataType: 'json'," & vbCrLf
		Response.Write "                success: function(res) {" & vbCrLf
		Response.Write "                    if (res.code == 1) {" & vbCrlf
		Response.Write "                        layer.msg(res.msg, {time: 1000, icon: 1}, function () {" & vbCrlf
		Response.Write "                            tableIn.reload({ where: {ChannelID:'"&ChannelID&"'} });" & vbCrlf
		Response.Write "                        });" & vbCrlf
		Response.Write "                    }else{" & vbCrlf
		Response.Write "                        layer.msg(res.msg,{time:1000,icon:2});" & vbCrLf
		Response.Write "                    }" & vbCrlf
		Response.Write "                }" & vbCrLf
		Response.Write "            });" & vbCrLf
		Response.Write "        });" & vbCrlf
		Response.Write "        table.on('tool(list)', function(obj) {" & vbCrLf
		Response.Write "            var data = obj.data;" & vbCrLf
		Response.Write "            if(obj.event === 'del'){" & vbCrLf
		Response.Write "                    layer.confirm('你确定要删除吗？', function(index){" & vbCrLf
		Response.Write "                    $.ajax({" & vbCrLf
		Response.Write "                        type: 'post'," & vbCrLf
		Response.Write "                        url: '?Action=Del'," & vbCrLf
		Response.Write "                        data: {ChannelID: '"&ChannelID&"', FileId:data.name}," & vbCrLf
		Response.Write "                        dataType: 'json'," & vbCrLf
		Response.Write "                        success: function(res) {" & vbCrLf
		Response.Write "                            if (res.code == 1) {" & vbCrLf
		Response.Write "                                layer.msg(res.msg,{time:1000,icon:1});" & vbCrLf
		Response.Write "                                obj.del();" & vbCrLf
		Response.Write "                            }else{" & vbCrLf
		Response.Write "                                layer.msg(res.msg,{time:1000,icon:2});" & vbCrLf
		Response.Write "                            }" & vbCrLf
		Response.Write "                        }" & vbCrLf
		Response.Write "                    });" & vbCrLf
		Response.Write "                    layer.close(index);" & vbCrLf
		Response.Write "                });" & vbCrLf
		Response.Write "            }" & vbCrLf
		Response.Write "        });" & vbCrLf
		Response.Write "    });" & vbCrLf
		Response.Write "</script>" & vbCrLf
		Response.Write "</body>" & vbCrLf & "</html>"
	End If
End Sub

Sub Add()
	Response.Write "<!DOCTYPE html>" & vbCrLf
	Response.Write "<head>" & vbCrLf
	Response.Write "<title>模板管理</title>" & vbCrlf
	Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" & vbCrLf
	Response.Write "<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1'>" & vbCrLf
	Response.Write "<meta name='apple-mobile-web-app-status-bar-style' content='black'>" & vbCrLf
	Response.Write "<meta name='apple-mobile-web-app-capable' content='yes'>" & vbCrLf
	Response.Write "<meta name='format-detection' content='telephone=no'>" & vbCrLf
	Response.Write "<link rel=""stylesheet"" type=""text/css"" href=""../fonts/font-awesome/css/font-awesome.min.css"" />" & vbCrLf
	Response.Write "<link rel='stylesheet' type='text/css' href='../Js/Codemirror/Codemirror.css'/>" & vbCrLf
	Response.Write "<link rel='stylesheet' type='text/css' href='../Plugins/editor/css/editormd.min.css'/>" & vbCrLf
	Response.Write "<link href='../Plugins/layui/css/layui.css' rel='stylesheet' type='text/css' />" & vbCrLf
	Response.Write "<link href='../Style/global.css' rel='stylesheet' type='text/css' />" & vbCrLf
	Response.Write "<link href='../Style/font.css' rel='stylesheet' type='text/css' />" & vbCrLf
	Response.Write "<script type='text/javascript'>" & vbCrLf
	Response.Write "var pc_file = '" & InstallDir & "';" & vbCrLf
	Response.Write "var admin_file = '" & AdminFolder & "/';" & vbCrLf
	Response.Write "</script>" & vbCrLf
	Response.Write "<script type='text/javascript' src='../Js/Admin.js'></script>" & vbCrLf
	Response.Write "<script type='text/javascript' src='../../Dialog/main.js'></script>" & vbCrLf
	Response.Write "<script type='text/javascript' src='../../Dialog/lhgcore.min.js'></script>" & vbCrLf
	Response.Write "<script type='text/javascript' src='../../Dialog/lhgcalendar.min.js'></script>" & vbCrLf
	Response.Write "<script src='../Js/Codemirror/Codemirror.js' type='text/javascript'></script>" & vbCrLf
	Response.Write "<script src='../Js/Codemirror/xml.js' type='text/javascript'></script>" & vbCrLf
	Response.Write "<script src='../Js/Codemirror/css.js' type='text/javascript'></script>" & vbCrLf
	Response.Write "<script src='../Js/Codemirror/javascript.js' type='text/javascript'></script>" & vbCrLf
	Response.Write "<script src='../Js/Codemirror/htmlmixed.js' type='text/javascript'></script>" & vbCrLf
	Response.Write "<script src='../Js/Codemirror/mirrorframe.js' type='text/javascript'></script>" & vbCrLf
	Response.Write "<script type=""text/javascript"" src=""../Plugins/layui/layui.js""></script>" & vbCrLf
	Response.Write "<script type=""text/javascript"" src=""../Plugins/clipboard/clipboard.min.js""></script>" & vbCrLf
	Response.Write "<script type=""text/javascript"" src=""../Plugins/editor/editormd.min.js""></script>" & vbCrLf
	Response.Write "</head>" & vbCrlf
	Response.Write "<body>" & vbCrlf
	Response.Write "<script language=""JavaScript"">" & vbCrlf
	Response.Write "function CssInsertCode(Val,Content) {" & vbCrlf
	Response.Write "if(Val != """" && Val != null){" & vbCrlf
	Response.Write "Val = Val.replace(""{$quot}"",""\"""");" & vbCrlf
	Response.Write "Val = Val.replace(""{$quot}"",""\"""");" & vbCrlf
	Response.Write "TemplateContent.replaceSelection(Val,TemplateContent.getCursor());" & vbCrlf
	Response.Write "TemplateContent.focus()" & vbCrlf
	Response.Write "}" & vbCrLf
	Response.Write "}" & vbCrLf
	Response.Write "$(function(){" & vbCrLf
	Response.Write "$(""#MobanSetting img"").mousemove(function(){" & vbCrLf
	Response.Write "layer.tips($(this).attr(""dname""),this,{tips: [1, '#000']});" & vbCrLf
	Response.Write "});" & vbCrLf
	Response.Write "$(""#MobanSetting img"").mouseout(function(){" & vbCrLf
	Response.Write "layer.closeAll();" & vbCrLf
	Response.Write "});" & vbCrLf
	Response.Write "})" & vbCrLf
	Response.Write "</script>" & vbCrlf
	Response.Write "<form class='layui-form layui-form-pane' action=""" & strFileName & """ method=""post"" name=""myform"">" & vbCrlf
	Response.Write "<div class=""admin-main fadeInUp animated"">" & vbCrlf
	Response.Write "    <fieldset class=""layui-elem-field layui-field-title"">" & vbCrlf
	Response.Write "        <legend>添加模板</legend>" & vbCrlf
	Response.Write "    </fieldset>" & vbCrlf
	Response.Write "    <div class=""layui-form-item"">" & vbCrlf
	Response.Write "        <label class=""layui-form-label"">文件名称：</label>" & vbCrlf
	Response.Write "        <div class=""layui-input-4"">" & vbCrlf
	Response.Write "            <input name=""TemplateName"" type=""text"" id=""TemplateName"" size=""50"" value="""" placeholder=""请输入文件名称"" lay-verify=""TemplateName"" class=""layui-input"">" & vbCrlf
	Response.Write "        </div>" & vbCrlf
	Response.Write "    </div>" & vbCrlf
	Response.Write "    <div class=""layui-form-item"">" & vbCrlf
	Response.Write "        <label class=""layui-form-label"">文件别名：</label>" & vbCrlf
	Response.Write "        <div class=""layui-input-4"">" & vbCrlf
	Response.Write "            <input name=""TemplateGetName"" type=""text"" id=""TemplateGetName"" size=""50"" value="""" placeholder=""请输入文件别名"" lay-verify=""TemplateGetName"" class=""layui-input"">" & vbCrlf
	Response.Write "        </div>" & vbCrlf
	Response.Write "    </div>" & vbCrlf
	Response.Write "    <div class=""layui-form-item"">" & vbCrlf
	Response.Write "        <label class=""layui-form-label"">模板类型：</label>" & vbCrlf
	Response.Write "        <div class=""layui-input-back"">" & vbCrlf
	Response.Write "            <input type=""radio"" name=""TemplateType"" value=""1"" title=""首页模版"" lay-verify=""TemplateType"" checked>" & vbCrlf
	Response.Write "            <input type=""radio"" name=""TemplateType"" value=""2"" title=""列表页模版"" lay-verify=""TemplateType"">" & vbCrlf
	Response.Write "            <input type=""radio"" name=""TemplateType"" value=""3"" title=""详情页模版"" lay-verify=""TemplateType"">" & vbCrlf
	Response.Write "            <input type=""radio"" name=""TemplateType"" value=""4"" title=""搜索页模版"" lay-verify=""TemplateType"">" & vbCrlf
	Response.Write "            <input type=""radio"" name=""TemplateType"" value=""5"" title=""公共模板"" lay-verify=""TemplateType"">" & vbCrlf
	Response.Write "        </div>" & vbCrlf
	Response.Write "    </div>" & vbCrlf
	Response.Write "    <div class=""layui-form-item layui-form-text"">" & vbCrlf
	Response.Write "        <label class=""layui-form-label"">内容：</label>" & vbCrlf
	Response.Write "        <div class=""layui-input-block"" style=""border:1px solid #e6e6e6;"">" & vbCrlf
	Response.Write "            <div id=""MobanSetting"">" & CssSelect("TemplateContent","mycss",ChannelSkinID) & "&nbsp;<b>使用标签：</b>[<a href='javascript:void(0);' onClick=""ItemDialogLabel('Test','常用标签','" & InstallDir & AdminFolder & "/Admin/Admin_ShowLabel.asp?type=TemplateContent',800,450,'TemplateContent');""><img src=""../Images/TemplateEditor/TemplateConfig.gif"" dname=""常用标签""/></a>&nbsp;&nbsp;<a href='javascript:void(0);' onClick=""ItemDialogLabel('Test','文字列表标签','" & InstallDir & AdminFolder & "/Admin/Admin_ShowLabel.asp?Action=List&ChannelID=1&type=TemplateContent',800,450,'TemplateContent');""><img src=""../Images/TemplateEditor/articleList.gif"" dname=""文字列表标签"" /></a>&nbsp;&nbsp;<a href='javascript:void(0);' onclick=""ItemDialogLabel('Test','图片标签','" & InstallDir & AdminFolder & "/Admin/Admin_ShowLabel.asp?Action=Image&ChannelID=1&type=TemplateContent',800,450,'TemplateContent');""><img src=""../Images/TemplateEditor/image.gif"" dname=""图片标签"" /></a>&nbsp;&nbsp;<a href='javascript:void(0);' onclick=""ItemDialogLabel('Test','Flash标签','" & InstallDir & AdminFolder & "/Admin/Admin_ShowLabel.asp?Action=Flash&ChannelID=1&type=TemplateContent',800,450,'TemplateContent');""><img src=""../Images/TemplateEditor/videoList.gif"" dname=""Flash标签"" /></a>&nbsp;&nbsp;<a href='javascript:void(0);' onclick=""ItemDialogLabel('Test','Flash标签','" & InstallDir & AdminFolder & "/Admin/Admin_ShowLabel.asp?Action=Flashqq&ChannelID=1&type=TemplateContent',800,450,'TemplateContent');""><img src=""../Images/TemplateEditor/imagePlayer.gif"" dname=""Flash标签"" /></a>&nbsp;&nbsp;<a href='javascript:void(0);' onclick=""ItemDialogLabel('Test','栏目标签','" & InstallDir & AdminFolder & "/Admin/Admin_ShowLabel.asp?Action=Class&ChannelID=1&type=TemplateContent',800,450,'TemplateContent');""><img src=""../Images/TemplateEditor/ZList.gif"" dname=""栏目标签"" /></a>]</div>"
	Response.Write "<div id=""editormd""></div>" & vbCrlf
	Response.Write "<textarea name=""TemplateContent"" id=""TemplateContent"" style=""display:none;"" lay-verify=""TemplateContent""></textarea>" & vbCrlf
	Response.Write "        <a href=""javascript:void(0);"" id=""copyCss"" class=""layui-btn layui-btn-normal""><i class=""layui-icon layui-icon-fonts-code""></i>复制</a>" & vbCrlf
	Response.Write "        </div>" & vbCrlf
	Response.Write "    </div>" & vbCrlf
	Response.Write "</div>" & vbCrlf
	Response.Write "<script type='text/javascript'>" & vbCrLf
	Response.Write "TemplateContent = editormd(""editormd"", {" & vbCrLf
	Response.Write "	width : ""100%""," & vbCrLf
	Response.Write "	height : ""300px""," & vbCrLf
	Response.Write "	watch : false," & vbCrLf
	Response.Write "	toolbar : false," & vbCrLf
	Response.Write "	codeFold : true," & vbCrLf
	Response.Write "	searchReplace : true," & vbCrLf
	Response.Write "	placeholder : ""请输入html代码""," & vbCrLf
	Response.Write "	value : document.getElementById(""TemplateContent"").value," & vbCrLf
	Response.Write "	theme : ""default""," & vbCrLf
	Response.Write "	mode : ""text/html""," & vbCrLf
	Response.Write "	path : '../Plugins/editor/lib/'" & vbCrLf
	Response.Write "});" & vbCrLf
	Response.Write "</script>" & vbCrLf
	Response.Write "<br>" & vbCrlf
	Response.Write "<br>" & vbCrlf
	Response.Write "<br>" & vbCrlf
	Response.Write "<br>" & vbCrlf
	Response.Write "<br>" & vbCrlf
	Response.Write "<br>" & vbCrlf
	Response.Write "<input name=""ChannelID"" type=""hidden"" id=""ChannelID"" value=""" & ChannelID & """><input type=""hidden"" name=""Action"" value=""SaveAdd"">" & Submit_Layui("提交添加","重新填写","确认要清空对话框内容？","javascript:history.back();","返回上一页","") & vbCrlf
	Response.Write "</form>" & vbCrlf
	Response.Write "<div id=""copyCssWrap"" class=""copyCssWrap layui-layer-wrap"">" & vbCrLf
	Response.Write "    <textarea id=""cssTextarea"" readonly=""readonly""></textarea>" & vbCrLf
	Response.Write "    <a href=""javascript:layer.closeAll('page');"" id=""copyCssBtn"" class=""layui-btn layui-btn-normal"" data-clipboard-target=""#cssTextarea"">一键复制</a>" & vbCrLf
	Response.Write "</div>" & vbCrLf
	Response.Write "<script>" & vbCrlf
	Response.Write "layui.use(['form'], function () {" & vbCrlf
	Response.Write "    var form = layui.form;" & vbCrlf
	Response.Write "    //监听复制事件" & vbCrlf
	Response.Write "    $(""#copyCss"").click(function () {" & vbCrLf
	Response.Write "        var currentCss = TemplateContent.getValue();" & vbCrLf
	Response.Write "        if (currentCss !== ''){" & vbCrLf
	Response.Write "            $('#copyCssWrap textarea').val(currentCss);" & vbCrLf
	Response.Write "            layer.open({" & vbCrLf
	Response.Write "                type: 1" & vbCrLf
	Response.Write "                ,title: '<i class=""layui-icon layui-icon-fonts-code""></i> 复制'" & vbCrLf
	Response.Write "                ,id: 'Copy_Css'" & vbCrLf
	Response.Write "                ,content: $('#copyCssWrap')" & vbCrLf
	Response.Write "                ,maxWidth: '100%'" & vbCrLf
	Response.Write "            });" & vbCrLf
	Response.Write "        }" & vbCrLf
	Response.Write "    });" & vbCrLf
	Response.Write "    var clipboard = new ClipboardJS('#copyCssBtn');" & vbCrlf
	Response.Write "    clipboard.on('success', function(e) {" & vbCrlf
	Response.Write "        layer.msg('已复制');" & vbCrlf
	Response.Write "        e.clearSelection();" & vbCrlf
	Response.Write "    });" & vbCrlf
	Response.Write "    //自定义表单验证" & vbCrlf
	Response.Write "    form.verify({" & vbCrlf
	Response.Write "        TemplateName: function (value, item) {" & vbCrlf
	Response.Write "            if (!value){" & vbCrlf
	Response.Write "                item.focus();" & vbCrlf
	Response.Write "                return ""文件名称不能为空！请填写！"";" & vbCrlf
 	Response.Write "            }" & vbCrlf
	Response.Write "        }," & vbCrlf
	Response.Write "        TemplateGetName: function (value, item) {" & vbCrlf
	Response.Write "            if (!value){" & vbCrlf
	Response.Write "                item.focus();" & vbCrlf
	Response.Write "                return ""文件别名不能为空！请填写！"";" & vbCrlf
 	Response.Write "            }" & vbCrlf
	Response.Write "        }," & vbCrlf
	Response.Write "        TemplateType: function (value, item) {" & vbCrlf
	Response.Write "            var val = $(""input:radio[name='TemplateType']:checked"").val();" & vbCrlf
	Response.Write "            if (!val){" & vbCrlf
	Response.Write "                item.focus();" & vbCrlf
	Response.Write "                return ""模板类型不能为空！请选择！"";" & vbCrlf
 	Response.Write "            }" & vbCrlf
	Response.Write "        }," & vbCrlf
	Response.Write "        TemplateContent: function (value, item) {" & vbCrlf
	Response.Write "            if (!TemplateContent.getValue()){" & vbCrlf
	Response.Write "                TemplateContent.focus();" & vbCrlf
	Response.Write "                return ""模板代码不能为空！请填写！"";" & vbCrlf
 	Response.Write "            }" & vbCrlf
	Response.Write "        }," & vbCrlf
	Response.Write "    });" & vbCrlf
	Response.Write "    //提交监听" & vbCrlf
	Response.Write "    form.on('submit(submit)', function (data) {" & vbCrlf
	Response.Write "        loading = layer.load(1, {shade: [0.1,'#fff']});" & vbCrlf
	Response.Write "        $.ajax({" & vbCrLf
	Response.Write "            type: 'post'," & vbCrLf
	Response.Write "            url: '?Action=SaveAdd'," & vbCrLf
	Response.Write "            data: {TemplateName: $('#TemplateName').val(), TemplateGetName: $('#TemplateGetName').val(), TemplateType: $(""input:radio[name='TemplateType']:checked"").val(), ChannelID: $('#ChannelID').val(), TemplateContent: TemplateContent.getValue()}," & vbCrLf
	Response.Write "            dataType: 'json'," & vbCrLf
	Response.Write "            success: function(res) {" & vbCrLf
	Response.Write "                layer.close(loading);" & vbCrlf
	Response.Write "                if(res.code > 0){" & vbCrlf
	Response.Write "                    layer.msg(res.msg,{icon: 1, time: 1000},function(){" & vbCrlf
	Response.Write "                        location.href = res.url;" & vbCrlf
	Response.Write "                    });" & vbCrlf
	Response.Write "                }else{" & vbCrlf
	Response.Write "                    layer.msg(res.msg,{icon: 2, time: 1000});" & vbCrlf
	Response.Write "                }" & vbCrlf
	Response.Write "            }" & vbCrLf
	Response.Write "        });" & vbCrLf
	Response.Write "    });" & vbCrlf
	Response.Write "});" & vbCrlf
	Response.Write "</script>" & vbCrlf
	Response.Write "</body>" & vbCrLf & "</html>"
End Sub

Sub Modify()
	Response.Write "<!DOCTYPE html>" & vbCrLf
	Response.Write "<head>" & vbCrLf
	Response.Write "<title>模板管理</title>" & vbCrlf
	Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" & vbCrLf
	Response.Write "<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1'>" & vbCrLf
	Response.Write "<meta name='apple-mobile-web-app-status-bar-style' content='black'>" & vbCrLf
	Response.Write "<meta name='apple-mobile-web-app-capable' content='yes'>" & vbCrLf
	Response.Write "<meta name='format-detection' content='telephone=no'>" & vbCrLf
	Response.Write "<link rel=""stylesheet"" type=""text/css"" href=""../fonts/font-awesome/css/font-awesome.min.css"" />" & vbCrLf
	Response.Write "<link rel='stylesheet' type='text/css' href='../Js/Codemirror/Codemirror.css'/>" & vbCrLf
	Response.Write "<link rel='stylesheet' type='text/css' href='../Plugins/editor/css/editormd.min.css'/>" & vbCrLf
	Response.Write "<link href='../Plugins/layui/css/layui.css' rel='stylesheet' type='text/css' />" & vbCrLf
	Response.Write "<link href='../Style/global.css' rel='stylesheet' type='text/css' />" & vbCrLf
	Response.Write "<link href='../Style/font.css' rel='stylesheet' type='text/css' />" & vbCrLf
	Response.Write "<script type='text/javascript'>" & vbCrLf
	Response.Write "var pc_file = '" & InstallDir & "';" & vbCrLf
	Response.Write "var admin_file = '" & AdminFolder & "/';" & vbCrLf
	Response.Write "</script>" & vbCrLf
	Response.Write "<script type='text/javascript' src='../Js/Admin.js'></script>" & vbCrLf
	Response.Write "<script type='text/javascript' src='../../Dialog/main.js'></script>" & vbCrLf
	Response.Write "<script type='text/javascript' src='../../Dialog/lhgcore.min.js'></script>" & vbCrLf
	Response.Write "<script type='text/javascript' src='../../Dialog/lhgcalendar.min.js'></script>" & vbCrLf
	Response.Write "<script src='../Js/Codemirror/Codemirror.js' type='text/javascript'></script>" & vbCrLf
	Response.Write "<script src='../Js/Codemirror/xml.js' type='text/javascript'></script>" & vbCrLf
	Response.Write "<script src='../Js/Codemirror/css.js' type='text/javascript'></script>" & vbCrLf
	Response.Write "<script src='../Js/Codemirror/javascript.js' type='text/javascript'></script>" & vbCrLf
	Response.Write "<script src='../Js/Codemirror/htmlmixed.js' type='text/javascript'></script>" & vbCrLf
	Response.Write "<script src='../Js/Codemirror/mirrorframe.js' type='text/javascript'></script>" & vbCrLf
	Response.Write "<script type=""text/javascript"" src=""../Plugins/layui/layui.js""></script>" & vbCrLf
	Response.Write "<script type=""text/javascript"" src=""../Plugins/clipboard/clipboard.min.js""></script>" & vbCrLf
	Response.Write "<script type=""text/javascript"" src=""../Plugins/editor/editormd.min.js""></script>" & vbCrLf
	Response.Write "<script src=""../Plugins/msg/msg-1.0.1.js""></script>" & vbCrLf
	Response.Write "</head>" & vbCrlf
	Response.Write "<body>" & vbCrlf
	Dim TemplateName,TemplateContent
	TemplateName=trim(request("TemplateName"))
	if TemplateName="" Then
		Response.Write IsSuccess("请指定Html文件名！",AdminFolder & "/Admin/" & strFileName & "?ChannelID="&ChannelID&"")
		Exit Sub
	end if
	Dim TmpCls
	Set TmpCls = New Cls_FileSystem
	if TmpCls.Chk_Exist(InstallDir&TemplateDir&ChannelDir&"/"&TemplateName,1)=False Then
		Response.Write IsSuccess("错误的文件名！",AdminFolder & "/Admin/" & strFileName & "?ChannelID="&ChannelID&"")
		Exit Sub
	end if
	If FoundErr=True Then Exit Sub
	TemplateContent = LoadFile(InstallDir&TemplateDir&ChannelDir&"/"&TemplateName)
	Response.Write "<script language=""javascript"">" & vbCrlf
	Response.Write "var currentMode = 1;" & vbCrlf
	Response.Write "//加载 layer 模块" & vbCrlf
	Response.Write "layui.use('layer', function(){" & vbCrlf
	Response.Write "	layer = layui.layer;" & vbCrlf
	Response.Write "});" & vbCrlf
	Response.Write "function CssInsertCode(Val,Content) {" & vbCrlf
	Response.Write "if(Val != """" && Val != null){" & vbCrlf
	Response.Write "Val = Val.replace(""{$quot}"",""\"""");" & vbCrlf
	Response.Write "Val = Val.replace(""{$quot}"",""\"""");" & vbCrlf
	Response.Write "TemplateContent.replaceSelection(Val,TemplateContent.getCursor());" & vbCrlf
	Response.Write "TemplateContent.focus()" & vbCrlf
	Response.Write "}" & vbCrLf
	Response.Write "}" & vbCrLf
	Response.Write "$(function(){" & vbCrLf
	Response.Write "$(""#MobanSetting img"").mousemove(function(){" & vbCrLf
	Response.Write "layer.tips($(this).attr(""dname""),this,{tips: [1, '#000']});" & vbCrLf
	Response.Write "});" & vbCrLf
	Response.Write "$(""#MobanSetting img"").mouseout(function(){" & vbCrLf
	Response.Write "layer.closeAll();" & vbCrLf
	Response.Write "});" & vbCrLf
	Response.Write "})" & vbCrLf
	Response.Write "</script>" & vbCrlf
	Response.Write "<input name=""ChannelID"" type=""hidden"" id=""ChannelID"" value=""" & ChannelID & """>" & vbCrlf
	Response.Write "<div id=""content"" style=""width: 100%;height:100%;position: fixed;left: 0px;word-wrap: break-word;"">" & vbCrLf
	Response.Write "    <div id=""topNav"" style=""background-color: #2b2e37; color:#009688; height: 38px;line-height: 38px;padding-left: 12px; margin-left:-1px;position: absolute; z-index: 99999999999;width: 100%;"">" & vbCrLf
	Response.Write "        <div style=""padding-left: 50px;"">" & vbCrLf
	Response.Write "            <button onClick=""javascript:history.back();"" accesskey=""c"">返回上一页[C]</button>" & vbCrLf
	Response.Write "            当前修改<span id=""currentTemplateType"">" & GetMobanTypeName(ChannelDir&"/"&TemplateName) & "</span>：文件名称：<input type=""text"" id=""TemplateName"" value=""" & TemplateName & """ readonly=""readonly"" style=""border: 0px; background-color: #2b2e37; overflow: hidden; color: #009688; width: 100px;""/>文件别名：<input type=""text"" id=""TemplateGetName"" value=""" & GetMobanName(ChannelDir&"/"&TemplateName) & """ style=""border: 0px; background-color: #2b2e37; overflow: hidden; color: #009688; width: 100px;""/>" & vbCrLf
	Response.Write "            <button id=""htmledit_mode"" onclick=""htmledit_mode();"" accesskey=""x"">代码模式[X]</button>" & vbCrLf
	Response.Write "            <span id=""baocuninit""><button id=""save"" onclick=""saveHtmlSource();"" accesskey=""s"">保存更改[S]</button></span>" & vbCrLf
	Response.Write "            <span>&nbsp;&nbsp;&nbsp;</span>" & vbCrLf
	Response.Write "            可用：" & vbCrLf
	Response.Write "            <span id=""MobanSetting"" style=""display:none;"">" & CssSelect("TemplateContent","mycss",ChannelSkinID) & "&nbsp;<b>使用标签：</b>[<a href='javascript:void(0);' onClick=""ItemDialogLabel('Test','常用标签','" & InstallDir & "Admin/Admin/Admin_ShowLabel.asp?type=TemplateContent',800,450,'TemplateContent');""><img src=""../Images/TemplateEditor/TemplateConfig.gif"" dname=""常用标签""/></a>&nbsp;&nbsp;<a href='javascript:void(0);' onClick=""ItemDialogLabel('Test','文字列表标签','" & InstallDir & "Admin/Admin/Admin_ShowLabel.asp?Action=List&ChannelID=1&type=TemplateContent',800,450,'TemplateContent');""><img src=""../Images/TemplateEditor/articleList.gif"" dname=""文字列表标签"" /></a>&nbsp;&nbsp;<a href='javascript:void(0);' onclick=""ItemDialogLabel('Test','图片标签','" & InstallDir & "Admin/Admin/Admin_ShowLabel.asp?Action=Image&ChannelID=1&type=TemplateContent',800,450,'TemplateContent');""><img src=""../Images/TemplateEditor/image.gif"" dname=""图片标签"" /></a>&nbsp;&nbsp;<a href='javascript:void(0);' onclick=""ItemDialogLabel('Test','Flash标签','" & InstallDir & "Admin/Admin/Admin_ShowLabel.asp?Action=Flash&ChannelID=1&type=TemplateContent',800,450,'TemplateContent');""><img src=""../Images/TemplateEditor/videoList.gif"" dname=""Flash标签"" /></a>&nbsp;&nbsp;<a href='javascript:void(0);' onclick=""ItemDialogLabel('Test','Flash标签','" & InstallDir & "Admin/Admin/Admin_ShowLabel.asp?Action=Flashqq&ChannelID=1&type=TemplateContent',800,450,'TemplateContent');""><img src=""../Images/TemplateEditor/imagePlayer.gif"" dname=""Flash标签"" /></a>&nbsp;&nbsp;<a href='javascript:void(0);' onclick=""ItemDialogLabel('Test','栏目标签','" & InstallDir & "Admin/Admin/Admin_ShowLabel.asp?Action=Class&ChannelID=1&type=TemplateContent',800,450,'TemplateContent');""><img src=""../Images/TemplateEditor/ZList.gif"" dname=""栏目标签"" /></a>]</span>"
	Response.Write "        </div>" & vbCrLf
	Response.Write "    </div>" & vbCrLf
	Response.Write "    <iframe name=""iframe"" id=""iframe"" frameborder=""0"" style=""width:100%;height:100%;margin-top: 38px;padding-bottom: 38px;box-sizing: border-box;"" src=""?Action=ModifyContent&TemplateName=" & TemplateName & "&ChannelID=" & ChannelID & """></iframe>" & vbCrLf
	Response.Write "    <div id=""htmlMode"" style=""width:100%;height:100%; display:none; padding-bottom: 38px;box-sizing: border-box;"">" & vbCrLf
	Response.Write "        <style>" & vbCrLf
	Response.Write "            .CodeMirror-linenumber{" & vbCrLf
	Response.Write "                padding:0px;" & vbCrLf
	Response.Write "                padding-left:1px;" & vbCrLf
	Response.Write "            }" & vbCrLf
	Response.Write "        </style>" & vbCrLf
	Response.Write "        <div id=""editormd"" style=""width:100%; height:100%; margin-top: 38px;""></div>" & vbCrLf
	Response.Write "        <textarea id=""html_textarea"" style=""display:none;""></textarea>" & vbCrLf
	Response.Write "    </div>" & vbCrLf
	Response.Write "</div>" & vbCrLf
	Response.Write "<script>" & vbCrLf
	Response.Write "//模式切换" & vbCrLf
	Response.Write "function htmledit_mode(){" & vbCrLf
	Response.Write "    msg.loading('切换中');" & vbCrLf
	Response.Write "    document.getElementById(""htmledit_mode"").style.display='';    //将 代码模式、智能模式切换的按钮显示。智能模式下，一直优惠智能模式、代码模式的切换按钮" & vbCrLf
	Response.Write "    if(currentMode == 1){" & vbCrLf
	Response.Write "        //由智能模式切换代码模式" & vbCrLf
	Response.Write "        document.getElementById(""iframe"").style.display='none';" & vbCrLf
	Response.Write "        document.getElementById(""iframe"").style.marginTop='0px';" & vbCrLf
	Response.Write "        document.getElementById(""htmlMode"").style.display='';" & vbCrLf
	Response.Write "        document.getElementById(""MobanSetting"").style.display='';" & vbCrLf
	Response.Write "        //判断一下，如果模版页面不是正常的HTML模版，那么在切换到代码模式时，不进行赋值textarea的操作" & vbCrLf
	Response.Write "        var html = '';" & vbCrLf
	Response.Write "        try {" & vbCrLf
	Response.Write "            html = getHtmlSource();" & vbCrLf
	Response.Write "        } catch(error) {}" & vbCrLf
	Response.Write "        if(html != ''){" & vbCrLf
	Response.Write "            //由智能模式切换代码模式" & vbCrLf
	Response.Write "            document.getElementById(""html_textarea"").value=getHtmlSource();" & vbCrLf
	Response.Write "            TemplateContent = editormd(""editormd"", {" & vbCrLf
	Response.Write "                width            : ""100%""," & vbCrLf
	Response.Write "                height           : ""100%""," & vbCrLf
	Response.Write "                watch            : false," & vbCrLf
	Response.Write "                toolbar          : false," & vbCrLf
	Response.Write "                codeFold         : true," & vbCrLf
	Response.Write "                searchReplace    : true," & vbCrLf
	Response.Write "                placeholder      : ""请输入html代码""," & vbCrLf
	Response.Write "                value            : document.getElementById(""html_textarea"").value," & vbCrLf
	Response.Write "                theme            : ""default""," & vbCrLf
	Response.Write "                mode             : ""text/html""," & vbCrLf
	Response.Write "                path             : '../Plugins/editor/lib/'" & vbCrLf
	Response.Write "            });" & vbCrLf
	Response.Write "        }" & vbCrLf
	Response.Write "        document.getElementById(""htmledit_mode"").innerHTML = '智能模式[X]';" & vbCrLf
	Response.Write "        currentMode = 2;" & vbCrLf
	Response.Write "    }else{" & vbCrLf
	Response.Write "        //由代码模式切换智能模式" & vbCrLf
	Response.Write "        document.getElementById(""iframe"").style.display='';" & vbCrLf
	Response.Write "        document.getElementById(""iframe"").style.marginTop='38px';" & vbCrLf
	Response.Write "        document.getElementById(""htmlMode"").style.display='none';" & vbCrLf
	Response.Write "        document.getElementById(""MobanSetting"").style.display='none';" & vbCrLf
	Response.Write "        //将editormd的值转到textarea中" & vbCrLf
	Response.Write "        document.getElementById(""html_textarea"").value = TemplateContent.getValue();" & vbCrLf
	Response.Write "        var o = document.getElementById(""iframe"");" & vbCrLf
	Response.Write "        ed = document.all ? o.contentWindow.document : o.contentDocument;" & vbCrLf
	Response.Write "        ed.open();" & vbCrLf
	Response.Write "        ed.write(TemplateContent.getValue());" & vbCrLf
	Response.Write "        ed.close();" & vbCrLf
	Response.Write "        " & vbCrLf
	Response.Write "        document.getElementById(""htmledit_mode"").innerHTML = '代码模式[X]';" & vbCrLf
	Response.Write "        currentMode = 1;" & vbCrLf
	Response.Write "    }" & vbCrLf
	Response.Write "    msg.close();" & vbCrLf
	Response.Write "}" & vbCrLf
	Response.Write "function getHtmlSource(){" & vbCrLf
	Response.Write "    return $(window.document).find(""#iframe"")[0].contentWindow.xnx3_getHtmlSource();" & vbCrLf
	Response.Write "}" & vbCrLf
	Response.Write "//保存HTML源代码" & vbCrLf
	Response.Write "function saveHtmlSource(){" & vbCrLf
	Response.Write "    //html源代码" & vbCrLf
	Response.Write "    var html;" & vbCrLf
	Response.Write "    if(currentMode == 1){" & vbCrLf
	Response.Write "        //傻瓜模式，再iframe中" & vbCrLf
	Response.Write "        html = getHtmlSource();" & vbCrLf
	Response.Write "    }else{" & vbCrLf
	Response.Write "        //开发者模式，在 editormd 中获取，（已不在textarea中，textarea只是切换智能模式与代码模式的中转站）" & vbCrLf
	Response.Write "        " & vbCrLf
	Response.Write "        //将editormd的值转到textarea中" & vbCrLf
	Response.Write "        document.getElementById(""html_textarea"").value = TemplateContent.getValue();" & vbCrLf
	Response.Write "        html = document.getElementById(""html_textarea"").value" & vbCrLf
	Response.Write "    }" & vbCrLf
	Response.Write "    if(!$('#TemplateName').val()){" & vbCrLf
	Response.Write "        IsAlertFocus('文件名称不能为空！请填写！','TemplateName');" & vbCrLf
	Response.Write "        return false;" & vbCrLf
	Response.Write "    }" & vbCrLf
	Response.Write "    if(!$('#TemplateGetName').val()){" & vbCrLf
	Response.Write "        IsAlertFocus('文件别名不能为空！请填写！','TemplateGetName');" & vbCrLf
	Response.Write "        return false;" & vbCrLf
	Response.Write "    }" & vbCrLf
	Response.Write "    msg.loading('保存中');" & vbCrLf
	Response.Write "    $.ajax({" & vbCrLf
	Response.Write "        type: 'post'," & vbCrLf
	Response.Write "        url: '?Action=SaveModify'," & vbCrLf
	Response.Write "        data: {TemplateName: $('#TemplateName').val(), TemplateGetName: $('#TemplateGetName').val(), ChannelID: $('#ChannelID').val(), TemplateContent: html}," & vbCrLf
	Response.Write "        dataType: 'json'," & vbCrLf
	Response.Write "        success: function(res) {" & vbCrLf
	Response.Write "            msg.close();" & vbCrLf
	Response.Write "            if(res.code > 0){" & vbCrlf
	Response.Write "                //msg.success(""保存成功"");" & vbCrLf
	Response.Write "                layer.msg(res.msg,{icon: 1, time: 1000},function(){" & vbCrlf
	Response.Write "                    location.href = res.url;" & vbCrlf
	Response.Write "                });" & vbCrlf
	Response.Write "            }else{" & vbCrlf
	Response.Write "                //msg.failure(data.msg);" & vbCrLf
	Response.Write "                layer.msg(res.msg,{icon: 2, time: 1000});" & vbCrlf
	Response.Write "            }" & vbCrlf
	Response.Write "        }" & vbCrLf
	Response.Write "    });" & vbCrLf
	Response.Write "}" & vbCrLf
	Response.Write "//Jquery layer 提示" & vbCrLf
	Response.Write "$(function(){" & vbCrLf
	Response.Write "    //编辑模式" & vbCrLf
	Response.Write "    var htmledit_mode_tipindex = 0;" & vbCrLf
	Response.Write "    $(""#htmledit_mode"").hover(function(){" & vbCrLf
	Response.Write "        htmledit_mode_tipindex = layer.tips('可以快速您网站当前的编辑模式<br/><b>智能模式</b>：想改哪里点哪里，点了直接改！修改时右键还会有更多的选择！<br/><b>代码模式</b>：以最原始代码的形式提供编辑。建议有一定编程基础或者稍微懂点的专业人士使用', '#htmledit_mode', {" & vbCrLf
	Response.Write "            tips: [2, '#0FA6A8'], //还可配置颜色" & vbCrLf
	Response.Write "            time:0," & vbCrLf
	Response.Write "            tipsMore: true," & vbCrLf
	Response.Write "            area : ['310px' , 'auto']" & vbCrLf
	Response.Write "        });" & vbCrLf
	Response.Write "    },function(){" & vbCrLf
	Response.Write "        layer.close(htmledit_mode_tipindex);" & vbCrLf
	Response.Write "    })" & vbCrLf
	Response.Write "    " & vbCrLf
	Response.Write "    " & vbCrLf
	Response.Write "    //保存按钮" & vbCrLf
	Response.Write "    var save_tipindex = 0;" & vbCrLf
	Response.Write "    $(""#save"").hover(function(){" & vbCrLf
	Response.Write "        save_tipindex = layer.tips('将您当前所操作的页面保存。保存后可预览查看，刷新一下看看其是否已改变', '#save', {" & vbCrLf
	Response.Write "            tips: [2, '#0FA6A8'], //还可配置颜色" & vbCrLf
	Response.Write "            time:0," & vbCrLf
	Response.Write "            tipsMore: true" & vbCrLf
	Response.Write "        });" & vbCrLf
	Response.Write "    },function(){" & vbCrLf
	Response.Write "        layer.close(save_tipindex);" & vbCrLf
	Response.Write "    })" & vbCrLf
	Response.Write "})" & vbCrLf
	Response.Write "//默认使用的是首页，那么顶部的导航，可用标签进行显示控制" & vbCrLf
	Response.Write "document.getElementById(""currentTemplateType"").innerHTML = '" & GetMobanTypeName(ChannelDir&"/"&TemplateName) & "';" & vbCrLf
	Response.Write "</script>" & vbCrLf
	Response.Write "</body>" & vbCrLf & "</html>"
End Sub

Sub SaveAdd()
	If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
		dim MobanID,ChannelID,TemplateName,TemplateGetName,TemplateContent
		ChannelID=Trim(Request.Form("ChannelID"))
		TemplateName=Trim(Request.Form("TemplateName"))
		TemplateGetName=Trim(Request.Form("TemplateGetName"))
		TemplateType=Trim(Request.Form("TemplateType"))
		TemplateContent=ShiftCharacterSave(Trim(Request.Form("TemplateContent")))
		If TemplateType="" Then TemplateType = 1
		
		If TemplateName="" Then
			Response.Write "{""code"":0,""msg"":""\u6587\u4ef6\u540d\u79f0\u4e0d\u80fd\u4e3a\u7a7a\uff01""}" & vbCrLf
			Response.End()
		End If
		If TemplateGetName="" Then
			Response.Write "{""code"":0,""msg"":""\u6587\u4ef6\u522b\u540d\u4e0d\u80fd\u4e3a\u7a7a\uff01""}" & vbCrLf
			Response.End()
		End If
		If TemplateContent="" Then
			Response.Write "{""code"":0,""msg"":""\u5185\u5bb9\u4e0d\u80fd\u4e3a\u7a7a\uff01""}" & vbCrLf
			Response.End()
		End If
		
		If FoundErr = True Then Exit Sub
		
		TemplateName = Replace(TemplateName,".html","")
		MobanID = GetNewID(Data_Name, "MobanID")
		sql="select * from "&Data_Name&" where MobanName='" & ChannelDir & "/" & TemplateName & ".html'"
		Call Exe_Conn(rs,sql,3)
		If Not (rs.BOF And rs.EOF) Then
			rs("MobanName")=ChannelDir & "/" & TemplateName & ".html"
			rs("MobanGetName")=TemplateGetName
			rs("MobanType")=TemplateType
			rs.Update
			rs.Close
			Set rs = Nothing
		Else
			rs.addnew
			rs("MobanID")=MobanID
			rs("MobanName")=ChannelDir & "/" & TemplateName & ".html"
			rs("MobanGetName")=TemplateGetName
			rs("MobanType")=TemplateType
			rs.Update
			rs.Close
			Set rs = Nothing
		End If
		Dim TmpCls
		Set TmpCls = New Cls_FileSystem
		If TmpCls.Chk_Exist(InstallDir&TemplateDir&ChannelDir&"/"&TemplateName&".html",1)=True Then
			Response.Write "{""code"":0,""msg"":""\u5df2\u7ecf\u5b58\u5728\u6b64\u6587\u4ef6\uff08"&TemplateName&".html\uff09\uff01""}" & vbCrLf
			Response.End()
		End If
		Call TmpCls.Make_Dir(InstallDir&TemplateDir)
		Call TmpCls.Make_Dir(InstallDir&TemplateDir&ChannelDir&"/")
		WriteTOFile InstallDir&TemplateDir&ChannelDir&"/"&TemplateName&".html",TemplateContent
		Set TmpCls = Nothing
		Response.Write "{""code"":1,""msg"":""\u6a21\u677f\u6dfb\u52a0\u6210\u529f\uff01"",""url"":""?ChannelID="&ChannelID&"""}" & vbCrLf
		Response.End()
		Exit Sub
	End If
End Sub

Sub SaveModify()
	If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
		dim MobanID,ChannelID,TemplateName,TemplateGetName,TemplateContent
		ChannelID=Trim(Request.Form("ChannelID"))
		TemplateName=Trim(Request.Form("TemplateName"))
		TemplateGetName=Trim(Request.Form("TemplateGetName"))
		TemplateContent=ShiftCharacterSave(Trim(Request.Form("TemplateContent")))
		TemplateContent=LoseHtml(TemplateName,TemplateContent)
		
		If TemplateName="" Then
			Response.Write "{""code"":0,""msg"":""\u6587\u4ef6\u540d\u79f0\u4e0d\u80fd\u4e3a\u7a7a\uff01""}" & vbCrLf
			Response.End()
		End If
		If TemplateGetName="" Then
			Response.Write "{""code"":0,""msg"":""\u6587\u4ef6\u522b\u540d\u4e0d\u80fd\u4e3a\u7a7a\uff01""}" & vbCrLf
			Response.End()
		End If
		If TemplateContent="" Then
			Response.Write "{""code"":0,""msg"":""\u5185\u5bb9\u4e0d\u80fd\u4e3a\u7a7a\uff01""}" & vbCrLf
			Response.End()
		End If
		
		If FoundErr = True Then Exit Sub
		
		TemplateName = Replace(TemplateName,".html","")
		MobanID = GetNewID(Data_Name, "MobanID")
		sql="select * from "&Data_Name&" where MobanName='" & ChannelDir & "/" & TemplateName & ".html'"
		Call Exe_Conn(rs,sql,3)
		If Not (rs.BOF And rs.EOF) Then
			rs("MobanName")=ChannelDir & "/" & TemplateName & ".html"
			rs("MobanGetName")=TemplateGetName
			rs.Update
			rs.Close
			Set rs = Nothing
		Else
			rs.addnew
			rs("MobanID")=MobanID
			rs("MobanName")=ChannelDir & "/" & TemplateName & ".html"
			rs("MobanGetName")=TemplateGetName
			rs.Update
			rs.Close
			Set rs = Nothing
		End If
		Dim TmpCls
		Set TmpCls = New Cls_FileSystem
		Call TmpCls.Make_Dir(InstallDir&TemplateDir)
		Call TmpCls.Make_Dir(InstallDir&TemplateDir&ChannelDir&"/")
		WriteTOFile InstallDir&TemplateDir&ChannelDir&"/"&TemplateName&".html",TemplateContent
		Set TmpCls = Nothing
		Response.Write "{""code"":1,""msg"":""\u6a21\u677f\u4fee\u6539\u6210\u529f\uff01"",""url"":""?ChannelID="&ChannelID&"""}" & vbCrLf
		Response.End()
		Exit Sub
	End If
End Sub

Sub Update()
	If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
		dim MobanID,ChannelID,TemplateName,TemplateGetName
		ChannelID=Trim(Request.Form("ChannelID"))
		TemplateName=Trim(Request.Form("TemplateName"))
		TemplateGetName=Trim(Request.Form("TemplateGetName"))
		
		If TemplateName="" Then
			Response.Write "{""code"":0,""msg"":""\u6587\u4ef6\u540d\u79f0\u4e0d\u80fd\u4e3a\u7a7a\uff01""}" & vbCrLf
			Response.End()
		End If
		If TemplateGetName="" Then
			Response.Write "{""code"":0,""msg"":""\u6587\u4ef6\u522b\u540d\u4e0d\u80fd\u4e3a\u7a7a\uff01""}" & vbCrLf
			Response.End()
		End If
		
		If FoundErr = True Then Exit Sub
		
		MobanID = GetNewID(Data_Name, "MobanID")
		sql="select * from "&Data_Name&" where MobanName='" & ChannelDir & "/" & TemplateName & "'"
		Call Exe_Conn(rs,sql,3)
		If Not (rs.BOF And rs.EOF) Then
			rs("MobanName")=ChannelDir & "/" & TemplateName
			rs("MobanGetName")=TemplateGetName
			rs.Update
			rs.Close
			Set rs = Nothing
		Else
			rs.addnew
			rs("MobanID")=MobanID
			rs("MobanName")=ChannelDir & "/" & TemplateName
			rs("MobanGetName")=TemplateGetName
			rs.Update
			rs.Close
			Set rs = Nothing
		End If
		Response.Write "{""code"":1,""msg"":""\u6587\u4ef6\u522b\u540d\u4fee\u6539\u6210\u529f\uff01"",""url"":""?ChannelID="&ChannelID&"""}" & vbCrLf
		Response.End()
		Exit Sub
	End If
End Sub

Sub ModifyContent()
	Response.Write "<script type='text/javascript'>var pc_file = '" & InstallDir & "';var admin_file = '" & AdminFolder & "/';</script>" & vbCrLf
	Response.Write "<script src=""../Plugins/htmledit/htmledit.js""></script>" & vbCrLf
	TemplateContent = LoadFile(InstallDir&TemplateDir&ChannelDir&"/"&Request.QueryString("TemplateName"))
	TemplateContent = Replace(TemplateContent,"{$InstallDir}",InstallDir,1,-1,1)
	TemplateContent = Replace(TemplateContent,"{$SkinDir}",SkinDir,1,-1,1)
	Response.Write TemplateContent
End Sub

Sub TemplatePreview()
	Dim TemplateName,HtmlContent
	Tit="模板样式预览"
	TemplateName=Request.QueryString("TemplateName")
	HtmlContent = ChannelTemplate(TemplateName,ChannelSkinID,ChannelID)
	HtmlContent = Html.ReadClass(HtmlContent)
	HtmlContent = Html.ReadClassName(HtmlContent)
	HtmlContent = Html.ReadChannelList(HtmlContent)
	HtmlContent = Html.ReadChannelPic(HtmlContent)
	HtmlContent = Html.ReadChannelFlash(HtmlContent)
	HtmlContent = Html.ReadChannelFlashqq(HtmlContent)
	HtmlContent = ReHtml(HtmlContent)
	Response.Write HtmlContent
End Sub

Sub DelAll()
	If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
		Dim MobanID,FileId,FileNum,FilePath
		ChannelID = Code_CLng(Trim(Code_Form("ChannelID")))
		FileId = Trim(Code_Form("FileId"))
		TopDir=Replace(InstallDir&TemplateDir&ChannelDir&"/","//","/")
		Call Exec(Rs,"Select Top 1 MobanID From ["&Data_Name&"] Where MobanName='" & ChannelDir & "/" & FileId & "'",2)
		If Rs.Eof Then
			MobanID = ""
			Rs.Close
		Else
			MobanID = Rs("MobanID")
			Rs.Close
		End If
		FileNum=0
		If instr(FileId,",")>0 Then
			FileId = Split(FileId,",")
			If Ubound(FileId) > -1 Then
				For i = 0 to Ubound(FileId)
					Call Exec("","Delete From "&Data_Name&" Where MobanName='" & ChannelDir & "/" & FileId & "'",0)
					Call Exec("","Update ["&Data_Name&"] Set MobanID=MobanID-1 Where MobanID>"&MobanID,0)
					FilePath = Server.MapPath(TopDir & Trim(FileId(i)))
					If Fso.FileExists(FilePath) Then
						Fso.DeleteFile FilePath,true
						FileNum = FileNum + 1
					End If
				Next
			End If
		Else
			Call Exec("","Delete From "&Data_Name&" Where MobanName='" & ChannelDir & "/" & FileId & "'",0)
			Call Exec("","Update ["&Data_Name&"] Set MobanID=MobanID-1 Where MobanID>"&MobanID,0)
			FilePath = Server.MapPath(TopDir & FileId)
			If Fso.FileExists(FilePath) Then
				Fso.DeleteFile FilePath,true
				FileNum = FileNum + 1
			End If
		End If
		Response.Write "{""msg"":""\u6210\u529f\u5220\u9664\u6587\u4ef6\uff08"& FileId &"\uff09\uff01"",""code"":1}"
		Response.End()
	End If
End Sub
%>